package com.nbsaas.boot.promote.rest.convert;

import com.nbsaas.boot.promote.data.entity.Coupon;
import com.nbsaas.boot.promote.api.domain.response.CouponResponse;

import com.nbsaas.boot.utils.BeanDataUtils;
import com.nbsaas.boot.rest.api.Converter;
import java.util.HashMap;
import java.util.Map;
/**
* 优惠券-实体对象转化成响应对象
*/

public class CouponResponseConvert  implements Converter<CouponResponse,Coupon> {

    @Override
    public CouponResponse convert(Coupon source) {
        CouponResponse  result = new  CouponResponse();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getShop()!=null){
                        result.setShop(source.getShop().getId());
                    }
                    if(source.getState()!=null){
                    Map<Integer,String> StateMap=new HashMap<>();
                        StateMap.put(1,"未使用");
                        StateMap.put(2,"已使用");
                        StateMap.put(3,"已过期");
                    String label=  StateMap.get(source.getState());
                    result.setStateName(label);
                    }
                    result.setState(source.getState());

                    try {
                        if(source.getCustomer()!=null){
                            result.setCustomerName(source.getCustomer().getName());
                        }
                    } catch (Exception ignored) { }

                    if(source.getCustomer()!=null){
                        result.setCustomer(source.getCustomer().getId());
                    }
        return result;
    }

}

